//
//  AppDelegate.m
//  myDemo2
//
//  Created by wuxueying on 14-4-13.
//
//

#import "AppDelegate.h"
#import "ViewController.h"
#import "Appirater.h"
#import "ACPReminder.h"
#import "ClusterPrePermissions.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [WXApi registerApp:@"wxcefa411f34485347"];
//    [self gotoComment];
//    [self clusterPrePermissions];
    return YES;
}

- (void)clusterPrePermissions {
    ClusterPrePermissions *photosPermissions = [ClusterPrePermissions sharedPermissions];
    [photosPermissions showPhotoPermissionsWithTitle:@"Access your photos?"
                                       message:@"Your message here"
                               denyButtonTitle:@"Not Now"
                              grantButtonTitle:@"Give Access"
                             completionHandler:^(BOOL hasPermission,
                                                 ClusterDialogResult userDialogResult,
                                                 ClusterDialogResult systemDialogResult) {
                             }];
    
    ClusterPrePermissions *contactsPermissions = [ClusterPrePermissions sharedPermissions];
    [contactsPermissions showContactsPermissionsWithTitle:@"Access your contacts?"
                                          message:@"Your message here"
                                  denyButtonTitle:@"Not Now"
                                 grantButtonTitle:@"Give Access"
                                completionHandler:^(BOOL hasPermission,
                                                    ClusterDialogResult userDialogResult,
                                                    ClusterDialogResult systemDialogResult) {
                                }];
    ClusterPrePermissions *locationsPermissions = [ClusterPrePermissions sharedPermissions];
    [locationsPermissions showLocationPermissionsWithTitle:@"Access your location?"
                                          message:@"Your message here"
                                  denyButtonTitle:@"Not Now"
                                 grantButtonTitle:@"Give Access"
                                completionHandler:^(BOOL hasPermission,
                                                    ClusterDialogResult userDialogResult,
                                                    ClusterDialogResult systemDialogResult) {
                                }];
    
}

- (void)gotoComment {
    [Appirater setAppId:@"770699556"];
    [Appirater setDaysUntilPrompt:1];
    [Appirater setUsesUntilPrompt:10];
    [Appirater setSignificantEventsUntilPrompt:-1];
    [Appirater setTimeBeforeReminding:2];
    [Appirater setDebug:YES];
    [Appirater appLaunched:YES];
}

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
    return [WXApi handleOpenURL:url delegate:self];
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    return [WXApi handleOpenURL:url delegate:self];
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    ACPReminder * localNotifications = [ACPReminder sharedManager];
    localNotifications.messages = @[@"You have out of the app!"];
    localNotifications.timePeriods = @[@(1),@(10),@(15)]; //days
    localNotifications.appDomain = @"com.mydomain.appName";
    localNotifications.randomMessage = NO; //By default is NO (optional)
    localNotifications.testFlagInSeconds = YES; //By default is NO (optional) --> For testing purpose only!
    localNotifications.circularTimePeriod = YES; // By default is NO (optional)
    [localNotifications createLocalNotification];
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
    [[ACPReminder sharedManager] checkIfLocalNotificationHasBeenTriggered];
}

@end
